var $ = require("../../utils/util.js"), api = require("../../utils/api"), cf = require("../../config"),
  notice = require("../../utils/notice");

Component({
  properties: {
    display: {
      type: Boolean, value: true, observer: function (newVal, oldVal, changedPath) {
        this.setData({show: newVal && !this.data.login})
      }
    },
    ck: {
      type: String, value: "refreshUser", observer: function (newVal, oldVal, changedPath) {//this.setData({show:newVal})
      }
    },
  },
  data: {show: !1, login: !1, step: 1, BAND: cf.config.BAND, BANDLOGO: cf.config.BANDLOGO1},
  // ready: function () {
  //     var t = this;
  //     wx.getSetting({
  //         success: function (e) {
  //             e.authSetting["scope.userInfo"] ? t.setData({show: !1,login:!0}) : t.setData({show:t.data.display&&!0,login:!1})
  //         }
  //     })
  // },
  ready: function () {
    var t = this;
    wx.getSetting({
      success: function (e) {
        e.authSetting["scope.userInfo"] && wx.getStorageSync('token') ? t.setData({
          show: !1, login: !0
        }) : t.setData({show: t.data.display, login: !1})
      }
    })
  },
  methods: {
    getUserInfo: function (e) {
      var t = this;
      $.wxlogin(e.detail, function (u) {
        t.setData({show: !u.phone, step: 2})
        notice.postNotificationName(t.data.ck, u)
      })
      
    },
    getPhoneNumber: function (e) {
      console.log('------getPhoneNumber come 111')
      var t = this, td = t.data
      if (!$.isAuth()) {
        console.log('------getPhoneNumber come 222')
        $.alertModal("请先授权登录成功之后再绑定手机号")
        return;
      } else {
        console.log('------getPhoneNumber come 333')
        $.sessionCheck()
      }
      if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
        $.alertModal("授权失败")
      } else {
        console.log('------getPhoneNumber come 555')
        wx.login({
          success: function (res) {
            $.post(api.jiemiwx, {
                iv: e.detail.iv,
                encryptedData: e.detail.encryptedData,
                code: res.code,
                hxscene: $.gcache("hxscene") || ''
              },
              function (r) {
                r.code == 0 ? (t.setData({show: !1}), $.alertModal("绑定成功")) : $.alertModal("绑定失败请重试")
              });
          }
        })
      }
    },
    guan: function (e) {
      var t = this, td = t.data;
      t.setData({show: !td.show, display: !1})
    },
    
  }
});